
<template>
    <div class="box">
        <div class='Login'>
        <div class="form">
            <el-input minlength="1" v-model="formData.adminname" placeholder="请输入用户名" class="name">
                <!-- 插槽 前缀图标 #是v-slot -->
                <template #prefix>
                    <el-icon>
                        <UserFilled />
                    </el-icon>
                </template>
            </el-input>
            <el-input clearable show-password v-model="formData.password" placeholder="请输入密码" class="psw">
                <template #prefix>
                    <el-icon>
                        <Lock />
                    </el-icon>
                </template>
            </el-input>
            <el-button class="login-btn" @click="loginClick">登录</el-button>
        </div>
    </div>
    </div>
</template>
<script>
import { ElMessage } from 'element-plus'
import { UserFilled, Lock } from '@element-plus/icons-vue'
import {useUserInfoStore} from '@/stores/user'
export default {

    data() {
        return {
            userInfoStore: useUserInfoStore(),
            formData: {
                adminname: "",
                password: ""
            }
        }
    },
    computed: {

    },
    methods: {

        loginClick() {
            // 登录成功进入首页
            if (this.formData.adminname == 'admin') {
                ElMessage.success('欢迎管理员登录');
            } else {
                ElMessage.success(`欢迎+${this.formData.adminname}登录`);
            }
            this.userInfoStore.changeUserInfo(this.formData)
            this.$router.push('/home')

        },
    },
    components: {
        UserFilled, Lock
    }
}
</script>

<style lang='scss'>
html,
body,
#app,
.box{
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
}

.Login {
    height: 100%;
    // width: 100%;
    background-color: #f5f5f5;
    display: flex;
    justify-content: center;
    align-items: center;

    .form {
        min-width: 300px;
        width: 450px;
        background-color: #fff;
        padding: 20px;
        border-radius: 10px;

        h2 {
            text-align: center;
        }

        .psw {
            margin: 20px 0;
        }

        .login-btn {
            background-color: #6cf;
            color: #fff;
        }
    }
}
</style>